﻿using System;
using System.Windows.Forms;
using System.IO;
using System.Reflection;

namespace ECP.Test
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
        }



        private void buttonHello_Click(object sender, EventArgs e)
        {
            try
            {
                WCFService.UserServiceClient uc = new WCFService.UserServiceClient();
                txtResult.AppendText("UserServiceClient" + uc.HelloMessage("蒋光") + "\r\n");
            }
            catch (Exception e1)
            {
                txtResult.AppendText("UserServiceClient" + e1.Message + "\r\n");
            }
            try
            {
                WebService.UserService u = new WebService.UserService();
                txtResult.AppendText("UserService" + u.HelloMessage("蒋光") + "\r\n");
            }
            catch (Exception e2)
            {
                txtResult.AppendText("UserServiceClient" + e2.Message + "\r\n");
            }
            //try
            //{
            //    ECP.WSClient.UserServiceClient uc = new WSClient.UserServiceClient();
            //    txtResult.AppendText("UserServiceClient" + uc.HelloMessage("蒋光") + "\r\n");
            //}
            //catch (Exception e2)
            //{
            //    txtResult.AppendText("UserServiceClient" + e2.Message + "\r\n");
            //}

            //try
            //{
            //    ECP.WCFClient.UserServiceProxy up = new WCFClient.UserServiceProxy();
            //    txtResult.AppendText("UserServiceProxy" + up.HelloMessage("蒋光") + "\r\n");
            //}
            //catch (Exception e2)
            //{
            //    txtResult.AppendText("UserServiceProxy" + e2.Message + "\r\n");
            //}
        }

        private void buttonUpdateInfo_Click(object sender, EventArgs e)
        {
            openFileDialog.ShowDialog();
            txtResult.AppendText(openFileDialog.FileNames.ToString());
            foreach (string item in openFileDialog.FileNames)
            {
                string header = @"
/*****************************************************************************
*        描述 :
*             文件描述
*        CLR版本:            3.5
*        创建者 :            蒋 光 
*        个人域名:           jiangguang.net.cn
*        命名空间名称:       {0}
*        文件名:             {1}
*        创建系统时间:       {2}
*        创建年份:           {3}
*
/*****************************************************************************/
{4}
";
                FileInfo f = new FileInfo(item);
                StreamReader sr = new StreamReader(item);

                string res = sr.ReadToEnd();
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.AppendFormat(header, item.Replace(@"G:\tfs\exceladdin\trunk\JG.MCP\", "").Replace("\\" + f.Name, ""), f.Name, f.CreationTime, f.CreationTime.Year, res);
                sr.Close();
                StreamWriter sw = new StreamWriter(item);
                sw.Write(sb.ToString());
                sw.Close();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            System.Reflection.Assembly ass = System.Reflection.Assembly.LoadFrom("ECP.Service.dll");
            Type[] types = ass.GetTypes();
            foreach (Type item in types)
            {

                string str = "        /// <summary>  \r\n      /// 创建{0}代理实例     \r\n   /// </summary>        /// <returns></returns>\r\n        public I{0} CreateBusinessCardService() \r\n        { \r\n         return new {0}Client();  }";

                txtResult.AppendText(str.Replace("{0}", item.Name));
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            System.Text.StringBuilder sbInterface = new System.Text.StringBuilder();
            string className = "className";
            sbInterface.Append(@"
/*****************************************************************************
*        描述 :
*             文件描述
*        CLR版本:            3.5
*        创建者 :            蒋 光 
*        个人域名:           jiangguang.net.cn
*        命名空间名称:       ECP.Service.Utilities.WCFClient
*        文件名:             {0}
*        创建系统时间:       2012-11-09 23:33
*        创建年份:           2012
*
/*****************************************************************************/
using System;
using System.Data;
using ECP.Interface;

namespace ECP.Service.Utilities.WCFClient
{
    public class ");

            sbInterface.Append(className);
            sbInterface.Append("Client");
            sbInterface.Append(":WCFClientBase<I");
            sbInterface.Append(className);
            sbInterface.Append(">,I");
            sbInterface.Append(className);
            sbInterface.AppendLine("{");
            sbInterface.Append("public ");
            sbInterface.Append(className);
            sbInterface.Append("Client():base(\"");
            sbInterface.Append(className);
            sbInterface.Append("\")");
            sbInterface.AppendLine("{");
            this.txtResult.Text = sbInterface.ToString();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.txtResult.Text = this.txtResult.Text.ToUpper();
        }


    }
}